

/*---------------------------------------------------------
   Initializes the effect. The data is a table of data 
   which was passed from the server.
---------------------------------------------------------*/
function EFFECT:Init( data )

	self.LifeTime = CurTime() + math.Rand( 10, 20 )
	self.EffectTime = CurTime() + (math.Rand( 2,4 ))
	self.Rand = math.random(1,4)
	self.Ang = data:GetAngle()
	self.For = self.Ang:Forward()

	local count = table.Count( VehicleGibs )
	local model = VehicleGibs[ math.random( 1,count ) ]
	if (model == nil) then model = "models/props_c17/oildrumchunk01d.mdl" end

	self.Entity:SetModel( model )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS ) 
	self.Entity:SetPos(data:GetOrigin() + (VectorRand() * math.random( 1, 16 )))
	local phys = self.Entity:GetPhysicsObject()
	
	if (!phys:IsValid()) then
		self.Entity:Remove()
		print("Error! "..model.." is not a valid prop model!\n")
	end
	
	self.Entity:SetCollisionGroup( COLLISION_GROUP_WEAPON )
	
	if ( phys && phys:IsValid() ) then
	
		phys:Wake()
		phys:SetAngle( Angle( math.Rand(0,359), math.Rand(0,359), math.Rand(0,359) ) )
		phys:SetVelocity((VectorRand() * math.Rand( 100, 150 )) + (self.For * 500))
		phys:AddAngleVelocity(Angle(math.random(-250,250),math.random(-250,250),math.random(-250,250)))
	
	end
	
end


/*---------------------------------------------------------
   THINK
   Returning false makes the entity die
---------------------------------------------------------*/
function EFFECT:Think( )

	if self.Rand == 4 then
		if self.EffectTime >= CurTime() then
			local effectdata = EffectData()
			effectdata:SetOrigin(self.Entity:GetPos())
			util.Effect("smoke_trail", effectdata)
		end
	end

	return self.LifeTime >= CurTime() 
	
end


/*---------------------------------------------------------
   Draw the effect
---------------------------------------------------------*/
function EFFECT:Render()

	self.Entity:DrawModel()

end



